package com.example.idachuappone.person.member;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.example.idachuappone.BaseActivity;
import com.example.idachuappone.R;
import com.example.idachuappone.person.method.UserInfoMethod;
import com.example.idachuappone.person.method.UserInfoMethod.CallBackString;
import com.example.idachuappone.utils.CheckUtil;
import com.example.idachuappone.utils.ComUtil;
import com.example.idachuappone.utils.MainToast;
import org.json.JSONException;
import org.json.JSONObject;

public class MemberYuEActivity extends BaseActivity implements OnClickListener {
    private Button btn_add_money;
    private Button btn_back;
    private Button btn_index;
    private Dialog dialog;
    private int memberType;
    private TextView tv_member_yue;
    private String yue;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_member_yu_e);
        this.memberType = getIntent().getIntExtra("memberType", 0);
        this.dialog = ComUtil.createCusProgressSmallBlackBgDialog(this);
        initView();
        initData();
    }

    private void initData() {
        this.dialog.show();
        if (CheckUtil.checkNet(this)) {
            UserInfoMethod.getUserYuE(this, new CallBackString() {
                public void onSuccess(String result) {
                    MemberYuEActivity.this.dialog.dismiss();
                    try {
                        MemberYuEActivity.this.yue = new JSONObject(result).optString("data");
                        MemberYuEActivity.this.tv_member_yue.setText("\uffe5" + ComUtil.FormatDistance(MemberYuEActivity.this.yue));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

                public void onFail() {
                    MemberYuEActivity.this.dialog.dismiss();
                    MainToast.show(MemberYuEActivity.this, MemberYuEActivity.this.getResources().getString(R.string.netFail), 0);
                }
            });
        } else {
            MainToast.show(this, getResources().getString(R.string.txt_network), 0);
        }
    }

    private void initView() {
        this.btn_index = (Button) findViewById(R.id.btn_index);
        this.btn_index.setOnClickListener(this);
        this.btn_add_money = (Button) findViewById(R.id.btn_add_money);
        this.btn_add_money.setOnClickListener(this);
        this.tv_member_yue = (TextView) findViewById(R.id.tv_member_yue);
        this.btn_back = (Button) findViewById(R.id.btn_back);
        this.btn_back.setOnClickListener(this);
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_back /*2131165198*/:
                Intent data = new Intent();
                data.putExtra("yue", this.yue);
                setResult(-1, data);
                finish();
            case R.id.btn_index /*2131165213*/:
                startActivity(new Intent(this, MemberYuEDetailActivity.class));
            case R.id.btn_add_money /*2131165344*/:
                Intent intent = new Intent(this, MemberTypeActivity.class);
                intent.putExtra("isMemberRecharege", true);
                startActivity(intent);
            default:
        }
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == 4) {
            Intent data = new Intent();
            data.putExtra("yue", this.yue);
            setResult(-1, data);
            finish();
        }
        return true;
    }
}
